package com.hzit.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.ItemCat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.hzit.manager.service.IItemCatService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 分类管理Controller
 *
 * @author wf
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/itemcat")
public class ItemCatController extends BaseController
{
    @Autowired
    private IItemCatService itemCatService;

    /**
     * 查询分类管理列表
     */
        @GetMapping("/list")
    public TableDataInfo list(ItemCat itemCat)
    {
        startPage();
        List<ItemCat> list = itemCatService.selectItemCatList(itemCat);
        return getDataTable(list);
    }

    /**
     * 以分类名为key，模板id为值就数据放到redis中
     * @return
     */
    @GetMapping("/findAll")
    public R<List<ItemCat>> findAll()
    {
        List<ItemCat> list = itemCatService.findAll();
        return  R.ok(list);
    }

    /**
     * 导出分类管理列表
     */
        @Log(title = "分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemCat itemCat)
    {
        List<ItemCat> list = itemCatService.selectItemCatList(itemCat);
        ExcelUtil<ItemCat> util = new ExcelUtil<ItemCat>(ItemCat.class);
        util.exportExcel(response, list, "分类管理数据");
    }

    /**
     * 获取分类管理详细信息
     */
        @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(itemCatService.selectItemCatById(id));
    }

    /**
     * 新增分类管理
     */
        @Log(title = "分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemCat itemCat)
    {
        return toAjax(itemCatService.insertItemCat(itemCat));
    }

    /**
     * 修改分类管理
     */
        @Log(title = "分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemCat itemCat)
    {
        return toAjax(itemCatService.updateItemCat(itemCat));
    }

    /**
     * 删除分类管理
     */
        @Log(title = "分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itemCatService.deleteItemCatByIds(ids));
    }
}
